package com.hqj.controller;

import com.hqj.entity.Area;
import com.hqj.service.AreaServiceI;
import com.hqj.util.ReturnValueUtil;
import com.hqj.util.TreeUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/ac")
public class AreaController extends BaseController<Area> {

    @Resource(name="areaServiceI")
    private AreaServiceI asi;

    @Override
    public String index() {
        return "pages/area/index";
    }

    @Override
    public String addEdit(HttpServletRequest req, Model model) {
        return "pages/area/add";
    }

    @RequestMapping("/findSelect")
    @ResponseBody
    public String findSelect(Area area) {
        List<Area> list = asi.find(area);
        return ReturnValueUtil.findData(list.size(),list);
    }

    @RequestMapping("/getAreaJsonTree")
    @ResponseBody
    public String getAreaJsonTree(Area area){
        List<Area> list = asi.find(area);
        return TreeUtil.createAreaTree(list);
    }
}
